package com.xuhaijian.service;

import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.xuhaijian.mapper.OrderPaymentMapper;
import com.xuhaijian.model.OrderPayment;
import com.xuhaijian.model.dto.OrderPaymentDto;
import com.xuhaijian.utils.JsonToObjUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;

@Service
public class OrderPaymentService {
 
    @Autowired
    private OrderPaymentMapper orderPaymentMapper;

    public List<OrderPayment> listByCondition(String orderNo) {
        LambdaQueryWrapper<OrderPayment> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(OrderPayment::getOrderNo,orderNo);
        return orderPaymentMapper.selectList(queryWrapper);
    }

    public List<OrderPayment> queryDataByParam(String path) {
        try {
            OrderPaymentDto orderPaymentDto = JsonToObjUtils.jsonToObj(path, OrderPaymentDto.class);
            LambdaQueryWrapper<OrderPayment> queryWrapper = Wrappers.lambdaQuery();
            queryWrapper.eq(OrderPayment::getOrderNo,orderPaymentDto.getOrderNo());
            queryWrapper.eq(OrderPayment::getPlanPeriod,orderPaymentDto.getPlanPeriod());
            queryWrapper.eq(OrderPayment::getRepaymentType,orderPaymentDto.getRepaymentType());
            return orderPaymentMapper.selectList(queryWrapper);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}